/**
*
*   GraphBuilder
*
*   builds a graph( an adjacency matrix ) given a list of student groups
*
*   @author Ranie Jade Ramiso
*
*/
#ifndef GRAPHBUILDER_H_INCLUDED
#define GRAPHBUILDER_H_INCLUDED
#include "../Entities/session.h"
namespace GraphBuilder{
    typedef std::vector<Session> SessionList;
    typedef std::vector<StudentGroup> StudentGroupList;

    SessionList createSessions(StudentGroupList &groups){
        SessionList ret;

        int groupSize = groups.size();

        for(int i = 0; i < groupSize; i++){
            StudentGroup studentGroup = groups[i];
            StudentGroup::SubjectList list = studentGroup.subjects();

            int listSize = list.size();

            for(int j = 0; j < listSize; j++){
                Subject* subject = list[j];
                if(subject->load() == 3){
                    Session a(studentGroup, *subject, 3);
                    ret.push_back(a);
                } else if(subject->load() == 5){
                    Session a(studentGroup, *subject, 3);
                    Session b(studentGroup, *subject, 2);
                    b.flag = true;
                    ret.push_back(a);
                    ret.push_back(b);
                }
            }
        }
        return ret;
    }

    void toMatrix(const SessionList list, int **destination){
        if(destination == NULL)
            return;
        int size = list.size();

        for(int i = 0; i < size; i++){
            for(int j = 0; j < size; j++){
                if(i!=j){
                    if(list[i].group.id() == list[j].group.id())
                        destination[i][j] = 1;
                    else
                        destination[i][j] = -1;
                } else{
                    destination[i][j] == 0;
                }
            }
        }
    }
}


#endif // GRAPHBUILDER_H_INCLUDED
